<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="include :: head('字典列表')"></head>
<body>
<div class="yadmin-body animated fadeIn">
    <div class="layui-form yadmin-search-area input">
        <form class="layui-form-item">
            <div class="layui-inline">
                <label for="name" class="layui-form-label">通知名称</label>
                <div class="layui-input-inline">
                     <input type="text" name="name" id="name" placeholder="字典名称" class="layui-input" />
                </div>
                <button lay-submit="" lay-filter="search" class="layui-btn layui-btn-sm layui-btn-primary table-action">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
                <button type="reset" lay-filter="search" class="layui-btn layui-btn-sm layui-btn-primary table-action">
                    <i class="layui-icon layui-icon-refresh"></i>
                </button>
            </div>
        </form>
    </div>
    <script type="text/html" id="toolbar">
        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add">
            <i class="layui-icon layui-icon-addition">新增</i>
        </button>
        <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
            <i class="layui-icon layui-icon-delete" title="删除">删除</i>
        </button>
    </script>
    <table class="layui-hide" id="table-list"></table>
    <script type="text/html" id="column-toolbar">
        <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
            <i class="layui-icon layui-icon-edit" title="编辑">编辑</i>
        </button>
    </script>
</div>
<script>
layui.extend({
    tablePlug: 'layui/extend/tablePlug',
}).use(['table', 'form', 'tablePlug'], function () {
    let table = layui.table, $ = layui.$, form = layui.form, tablePlug = layui.tablePlug;
    tablePlug.smartReload.enable(true);
    table.render({
        elem: '#table-list',
        url: '/dict/list',
        method: 'post',
        dataType: 'JSON',
        page: true,
        toolbar: '#toolbar',
        smartReloadModel: true,
        cols: [
            [
                {type: 'checkbox'},
                {
                    type: "numbers", title: '序号', minWidth: 80, templet: function (index) {
                        return index + 1;
                    }
                },
                {field: 'name', title: '名称', minWidth: 80},
                {
                    field: 'sign', title: '类型', minWidth: 80, templet: function (res) {
                        if (res.sign == "Y") {
                            return "系统类型";
                        }
                        return "类型值";
                    }
                },
                {field: 'code', title: '字典编码', minWidth: 80},
                {field: 'sort', title: '排序', minWidth: 80},
                {field: 'description', title: '备注', minWidth: 80},
                {fixed: 'right', title: '操作', align: 'center', toolbar: '#column-toolbar'}
            ]
        ], parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "data": res.data, //解析数据列表
                "count": res.recordsTotal
            };
        }
    });
    
    // 工具条点击事件
    table.on('toolbar', function (obj) {
        if (obj.event === 'add') {
            editView("/dict/add", "添加通知");
        } else if (obj.event === 'del') {
            layer.confirm('真的删除行么?', function (index) {
                let selectData = table.checkStatus('table-list').data;
                if (selectData.length > 0) {
                    let idsArray = [];
                    for (let i = 0; i < selectData.length; i++) {
                        idsArray.push(selectData[i].deptId);
                    }
                    let ids = idsArray.toString();
                    delReq(ids, '/dict/del')
                    layer.close(index);
                }
            });
        }
    });
    
    table.on('tool', function (obj) {
        let data = obj.data, event = obj.event;
        if (event === 'edit') {
            editView("/dict/update?id=" + data.dictId, "编辑通知");
        }
    });
    
    form.on('submit(search)', function (form) {
        table.reload('table-list', {
            where: form.field
        });
        return false;
    });
});
</script>
</body>
</html>